package com.atgugui.commonutils;

import java.util.Random;

/**
 * 验证码工具类
 */
public class CheckCodeUtils {
    private final static Random RANDOM = new Random();
    private final static String TEMPLATE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private final static int LEN = 6; // 默认长度

    public static String GeneratorCheckCode(int len) {
        StringBuilder checkCode = new StringBuilder();
        for (int i = 0; i < len; i++) {
            checkCode.append(TEMPLATE.charAt(RANDOM.nextInt(TEMPLATE.length())));
        }
        return checkCode.toString();
    }

    // 默认生成长度为6
    public static String GeneratorCheckCode() {
        StringBuilder checkCode = new StringBuilder();
        for (int i = 0; i < LEN; i++) {
            checkCode.append(TEMPLATE.charAt(RANDOM.nextInt(TEMPLATE.length())));
        }
        return checkCode.toString();
    }

    // 生成激活信息
    public static String GeneratorMailActiveCheckMessage(String checkCode, Long expire) {
        return "您好,谷粒在线教育平台注册激活邮件,本次激活码为:"
                + "{" + checkCode + "}" + "请您在:" + expire + "分钟之内激活";
    }
}
